package com.liu.design.building.prototype;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author LIU
 * @version 1.0
 * @date 2024/5/3 10:54
 * @description 原型模式
 * 浅拷贝：jdk实现
 * 深拷贝：序列化实现
 */
public class Test {
    public static void main(String[] args) {

        ConcretePrototype prototype = new ConcretePrototype();
        prototype.setAge(20);
        prototype.setName("小明");

        ArrayList<String> list = new ArrayList<>();
        list.add("游泳");
        list.add("java");
        prototype.setHobbies(list);

//        ConcretePrototype deepClone = prototype.clone();
        ConcretePrototype deepClone = prototype.deepClone();
        deepClone.getHobbies().add("开车");

        System.out.println(prototype);
        System.out.println(deepClone);
    }
}
